//
//  ZMyAddressDeleteAlertView.m
//  DistributorAB
//
//  Created by LZY on 2019/10/12.
//  Copyright © 2019 主事丫环. All rights reserved.
//

#import "ZMyAddressDeleteAlertView.h"

@implementation ZMyAddressDeleteAlertView

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self setupViewAction];
    }
    return self;
}
#pragma mark - 界面布局方法
- (void)setupViewAction{
    
    self.backgroundColor = kColorWithHex(0xb1b0af);
    
    
    UIView *viewCenter = [UIView new];
    viewCenter.backgroundColor = kColorWithHex(0xffffff);
    viewCenter.layer.cornerRadius = 6.0;
    viewCenter.layer.masksToBounds = YES;
    [self addSubview:viewCenter];
    [viewCenter mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self);
        make.size.mas_equalTo(CGSizeMake(331, 239));
    }];
    
    UIImageView *ivSuccess = [UIImageView new];
    ivSuccess.image = [UIImage imageNamed:@"user_alert_icon"];
    [viewCenter addSubview:ivSuccess];
    
    UILabel *lblNotice = [UILabel new];
    lblNotice.text = @"确认删除?";
    lblNotice.textColor = kColorWithHex(0x333333);
    lblNotice.font = [UIFont systemFontOfSize:16];
    lblNotice.textAlignment = NSTextAlignmentCenter;
    [viewCenter addSubview:lblNotice];
    
    
    UIButton *btnOK = [UIButton buttonWithType:UIButtonTypeCustom];
    [viewCenter addSubview:btnOK];
    [btnOK setTitle:@"确认" forState:UIControlStateNormal];
    [btnOK setTitleColor:kColorWithHex(0x70be68) forState:UIControlStateNormal];
    btnOK.titleLabel.font = [UIFont systemFontOfSize:14];
    [btnOK setBackgroundColor:kColorWithHex(0xffffff)];
    btnOK.layer.cornerRadius = 4.0;
    btnOK.layer.masksToBounds = YES;
    btnOK.layer.borderColor = kColorWithHex(0x70be68).CGColor;
    btnOK.layer.borderWidth = 1;
    [btnOK addTarget:self action:@selector(btnOKClickAction:) forControlEvents:UIControlEventTouchUpInside];
    
    UIButton *btnCancle = [UIButton buttonWithType:UIButtonTypeCustom];
    [viewCenter addSubview:btnCancle];
    [btnCancle setTitle:@"取消" forState:UIControlStateNormal];
    [btnCancle setTitleColor:kColorWithHex(0xffffff) forState:UIControlStateNormal];
    btnCancle.titleLabel.font = [UIFont systemFontOfSize:14];
    [btnCancle setBackgroundColor:kColorWithHex(0x70be68)];
    btnCancle.layer.cornerRadius = 4.0;
    btnCancle.layer.masksToBounds = YES;
    [btnCancle addTarget:self action:@selector(btnCancleClickAction:) forControlEvents:UIControlEventTouchUpInside];
    
    [ivSuccess mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(viewCenter.mas_centerX);
        make.top.equalTo(viewCenter.mas_top).offset(26);
        make.size.mas_equalTo(CGSizeMake(91, 65));
    }];
    
    [lblNotice mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(viewCenter.mas_centerX);
        make.top.equalTo(ivSuccess.mas_bottom).offset(21);
    }];
    
    
    [btnCancle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(viewCenter.mas_leading).offset(45);
        make.bottom.equalTo(viewCenter.mas_bottom).offset(-22);
        make.size.mas_equalTo(CGSizeMake(113, 36));
    }];
    
    [btnOK mas_makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.equalTo(viewCenter.mas_trailing).offset(-45);
        make.bottom.equalTo(viewCenter.mas_bottom).offset(-22);
        make.size.mas_equalTo(CGSizeMake(113, 36));
    }];
}

#pragma mark - 交互方法
//显示
- (void)showView{
    UIWindow *window = [[[UIApplication sharedApplication] delegate] window];
    self.frame = window.bounds;
    [window addSubview:self];
}
//关闭
- (void)dismissView{
    [self removeFromSuperview];
}
//确定
- (void)btnOKClickAction:(UIButton *)sender{
//    if (self.btnOkClick) {
//        [self btnOkClick];
//        [self dismissView];
//    }
    if (self.delegate && [self.delegate respondsToSelector:@selector(alertViewBtnOkClick:)]) {
        [self.delegate alertViewBtnOkClick:_indexPath];
        [self dismissView];
    }
}
//取消
- (void)btnCancleClickAction:(UIButton *)sender{
    [self dismissView];
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
